#include "SoundManagerThread.h"
SoundManagerThread::SoundManagerThread(SoundManager &soundManager):m_soundManager(soundManager)
{
	stop = false;

}

SoundManagerThread::~SoundManagerThread()
{
	Stop();
}

int SoundManagerThread::Start()
{
	if (JThread::IsRunning())
	{
		return -1;
	}
	if (!stop_mutex.IsInitialized())
	{
		if (stop_mutex.Init()<0)
		{
			return -2;
		}
	}
	stop = false;
	if (JThread::Start()<0)
	{
		return -3;
	}
	return 0;
}

void SoundManagerThread::Stop()
{
	if (!JThread::IsRunning())
	{
		return ;
	}
	stop_mutex.Lock();
	stop = true;
	stop_mutex.Unlock();
	bool done = false;
	if (JThread::IsRunning())
	{
		JThread::Kill();
	}
	stop = false;
}

void* SoundManagerThread::Thread()
{
	JThread::ThreadStarted();
	while(stop == false)
	{
		m_soundManager.Process();
	}
	return NULL;
}